#ifndef COMBINED_H
#define COMBINED_H

#include <QDialog>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QWidget>
#include <QScrollArea>
#include <QVBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QGroupBox>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QMessageBox>
#include <QFile>
#include <QFileInfo>
#include <QDir>
#include <QSqlQuery>
#include <QSqlError>
#include <QMovie>
#include <QPixmap>
#include <QMap>
#include <QSqlDatabase>
#include <QDateTime>
#include "paymentwidget.h"
//订单详情数据结构
struct OrderDetail {
    int orderId;
    int userId;
    QString totalPrice;
    QDateTime createTime;
    QString status;
    QString address;
    QString imagePath;
    double shippingFee;
    double discount;

    struct UserInfo {
        QString username;
        QString phone;
    } user;

    struct ProductItem {
        int productId;
        QString name;
        double price;
        int quantity;
        QString category;
        QString status;
        QString imagePath;
    };
    QList<ProductItem> products;

    struct CouponInfo {
        QString code;
        QString type;
        double value;
        double minAmount;
        QDateTime startTime;
        QDateTime endTime;
        QString status;
    } coupon;

    struct ActivityInfo {
        QString name;
        QString type;
        double discountRate;
        QString condition;
        QDateTime startTime;
        QDateTime endTime;
        QString status;
    } activity;
};

struct OrderSummary {
    int orderId;
    double amount;
    QString date;
    double totalPrice;
    QDateTime createTime;
    QString status;

    // 根据需要添加其他字段（如商品信息、状态等）
};

struct ProductDetail {
    int productId;
    QString name;
    double price;
    int quantity;
    QString imagePath; // 可选：商品图片路径
};

namespace Ui {
class orderStatusWidget;
}

class ProductItemWidget : public QWidget
{
    Q_OBJECT
public:
    explicit ProductItemWidget(QWidget *parent = nullptr);
    ~ProductItemWidget();



    // 手动设置产品信息
    void setProductInfo(const QString &name, const QString &imagePath, double price, int quantity);

signals:

private slots:

private:
    QLabel *m_imageLabel;
    QLabel *m_nameLabel;
    QLabel *m_priceLabel;
    QLabel *m_quantityLabel;
    QNetworkAccessManager *m_networkManager;
    QMap<QNetworkReply*, ProductItemWidget*> m_activeDownloads;


    QSqlDatabase db;
};

class orderStatusWidget : public QDialog
{
    Q_OBJECT

public:
    explicit orderStatusWidget(QWidget *parent = nullptr);
    ~orderStatusWidget();



    // 设置订单信息
    void setOrderInfo(const QString &orderId,
                      const QDateTime &orderTime,
                      const QString &status,
                      const QString &paymentMethod);

    // 添加商品信息
    void addProduct(const QString &name,
                    const QString &imageUrl,
                    double price,
                    int quantity);

    void setShippingInfo(const QString &name,
                           const QString &contact,
                           const QString &address,
                           const QString &logistics,
                           const QString &trackingNumber);
    // 设置价格信息
    void setPriceInfo(double subtotal,
                      double shippingFee,
                      double discount,
                      double total);

    // 更新订单状态
    void updateOrderStatus(const QString &status);
    void clearProducts();
    void initLayout(); // 新增初始化布局函数，替代 addSeparators

    void showDefaultImage(QLabel *imageLabel);
    bool eventFilter(QObject *obj, QEvent *event);

signals:
    void paymentRequested(const QString &orderId);
    void logisticsTrackRequested(const QString &trackingNumber);
    void confirmReceiptRequested(const QString &orderId);
    void paymentCompleted(const QString &orderId);


private slots:
    void on_paymentButton_clicked();
    void on_trackButton_clicked();
    void on_confirmReceiptButton_clicked();
    void on_cancelOrderButton_clicked();
    void handlePaymentCompleted(const QString &orderId);

private:
    void setupProductsLayout(const QVector<ProductDetail> &products);
    QFrame* createSeparatorLine();

    Ui::orderStatusWidget *ui;
    QNetworkAccessManager *m_networkManager;

    QString m_orderId;
    QString m_trackingNumber;
    double m_totalAmount;
};

#endif // COMBINED_H


